package com.mingqijia.gassafety.webserver.service.impl;

import com.mingqijia.gassafety.webserver.response.sk.AlarmSupplierListVo;
import com.mingqijia.gassafety.webserver.response.sk.ConsoleSkSupplierListResponse;
import com.mingqijia.gassafety.webserver.service.EquipmentManufacturerService;
import com.mingqijia.gassafety.webserver.service.cmp.EquipmentCmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 控制器表 服务实现类
 * </p>
 *
 * @author wanghai
 * @since 2022-02-21
 */
@Service
@Slf4j
public class EquipmentManufacturerServiceImpl implements EquipmentManufacturerService {

    @Autowired
    private EquipmentCmpService equipmentCmpService;

    @Override
    public List<AlarmSupplierListVo> queryList() {
        ConsoleSkSupplierListResponse response = equipmentCmpService.supplierListRequest();
        if (null != response && null != response.getData() && null != response.getData()) {
            log.info("结束调用厨房查询厂商接口，返回数据长度：{}", response.getData().size());
            return response.getData();
        }
        log.info("结束调用厨房查询厂商接口，未找到相关数据");
        return new ArrayList<>();
    }

    @Override
    public Map<String, AlarmSupplierListVo> queryMap() {
        ConsoleSkSupplierListResponse response = equipmentCmpService.supplierListRequest();
        if (null != response && null != response.getData() && null != response.getData()) {
            log.info("结束调用厨房查询厂商接口，返回数据长度：{}", response.getData().size());
            return response.getData().stream()
                    .collect(Collectors.toMap(
                            AlarmSupplierListVo::getAlarmSystemCode,
                            e -> e,
                            (k1, k2) -> k2
                    ));
        }
        log.info("结束调用厨房查询厂商接口，未找到相关数据");
        return new HashMap<>();
    }
    @Override
    public Map<String, String> queryNameMap() {
        ConsoleSkSupplierListResponse response = equipmentCmpService.supplierListRequest();
        if (null != response && null != response.getData() && null != response.getData()) {
            log.info("结束调用厨房查询厂商接口，返回数据长度：{}", response.getData().size());
            return response.getData().stream()
                    .collect(Collectors.toMap(
                            AlarmSupplierListVo::getAlarmSystemCode,
                            AlarmSupplierListVo::getMsName,
                            (k1, k2) -> k2
                    ));
        }
        log.info("结束调用厨房查询厂商接口，未找到相关数据");
        return new HashMap<>();
    }
}